home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE18
/
EX5.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-26
|
3KB
|
90 lines
#include <genstub.c>
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static UINT wClipFormat = 0;
switch (uMsg) /* process windows messages */
{
case WM_CREATE:
// register special format
wClipFormat = RegisterClipboardFormat( "SPECIAL" );
OpenClipboard( hWnd );
EmptyClipboard( );
SetClipboardData( wClipFormat, NULL); // delayed rendering
CloseClipboard( );
break ;
case WM_RENDERALLFORMATS:
case WM_RENDERFORMAT:
{
// receive request to render clipboard data
HANDLE hMem; // allocation of data to be stored in clipboard
LPVOID lpData; // pointer to access data
OpenClipboard( hWnd );
EmptyClipboard( );
hMem = GlobalAlloc( GHND, 64 );
lpData = GlobalLock( hMem );
lstrcpy( lpData, "Special data in clipboard" );
SetClipboardData( wClipFormat, hMem );
GlobalUnlock( hMem );
CloseClipboard( );
}
break;
case WM_PAINT: /* show status of clipboard format */
{
PAINTSTRUCT ps; // paint parameters
BeginPaint( hWnd, &ps );
OpenClipboard( hWnd );
if ( IsClipboardFormatAvailable( wClipFormat ) )
{ // if the special clipboard format is present in clipboard
char cBuf[128];
HANDLE hClipMem = GetClipboardData( wClipFormat );
HANDLE hMem = GlobalAlloc( GHND, GlobalSize (hClipMem) );
// get access to data in both buffers to store local
LPVOID lpData = GlobalLock( hMem );
LPVOID lpClip = GlobalLock( hClipMem );
// copy into local buffer
lstrcpy( lpData, lpClip );
TextOut( ps.hdc, 10, 10, cBuf, wsprintf( cBuf,
"Special CB Format contains: %s", lpData ) );
GlobalUnlock( hMem );
GlobalFree( hMem );
// You must UNLOCK clipboard data but you may NEVER free the data.
GlobalUnlock( hClipMem );
}
CloseClipboard( );
EndPaint( hWnd, &ps );
}
break;
case WM_COMMAND:
switch (wParam)
{
case IDM_TEST:
InvalidateRect( hWnd, NULL, TRUE );
break ;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
#include <aboutopt.c>
}
break;
#include <rbutton.c>
case WM_DESTROY: /* stop application */
PostQuitMessage (0) ;
break ;
default: /* default windows message processing */
return DefWindowProc (hWnd, uMsg, wParam, lParam) ;
}
return (0L) ;
}
#include <about.c>